﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace TomNet.Attributes
{
    /// <summary>
    /// 密码正则表达式校验
    /// </summary>
    public class PasswordAttribute : BaseAttribute
    {
        public override string Error
        {
            get
            {
                if (base.Error != null)
                {
                    return base.Error;
                }
                return "非有效密码";
            }

            set => base.Error = value;
        }
        public override bool Validate(object value)
        {
            var regex = new Regex(@"(?=^.{8,20}$)(?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?!.*\s).*$");
            return value == null || regex.Match(value.ToString()).Success;
        }
    }
}
